package com.bys.ots.model;

import microsoft.exchange.webservices.data.core.ExchangeService;
import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
import microsoft.exchange.webservices.data.credential.ExchangeCredentials;
import microsoft.exchange.webservices.data.credential.WebCredentials;

import java.net.URI;

/**
 * @program: Supply Center
 * @description:
 * @author: Huizhe Yu
 * @create: 2019-07-12 15:32
 */
public abstract class AbstractMailService {

    public ExchangeService service;

    public void initExchangeService(String username,String password,String demand) throws Exception{
        service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
        ExchangeCredentials credentials = new WebCredentials(username,password);
        service.setCredentials(credentials);
        try {
            service.setUrl(new URI("https://" + demand + "/ews/exchange.asmx"));
        } catch (Exception e) {
            throw new Exception("初始化exchange服务失败。" , e);
        }
    }
}
